package cn.wolfcode.rbac.service.impl;

import cn.wolfcode.rbac.domain.Employee;
import cn.wolfcode.rbac.mapper.DepartmentMapper;
import cn.wolfcode.rbac.service.ILoginService;
import cn.wolfcode.rbac.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2020/6/12 0012.
 */
@Service
public class LoginServiceImpl implements ILoginService {
    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public void login(String username, String password) {
        //1  上数据库中根据账号和密码去查询 是否有数据
        Employee e = departmentMapper.selectEmpByUsernameAndPassword(username,password);
        //2 如果没有数据抛出一个异常, 异常信息就是账号或者密码不正确
        if(e == null){
            throw new RuntimeException("账号或者密码不正确");
        }

        //如果正常没有抛出异常,说明用户账号和密码输入的都是正确的, 那么把查询出来的对象放入到session当中
        UserContext.setCurrent(e);
    }

    @Override
    public void regist(Employee employee) {

    }

    @Override
    public void sendVerfiCode(String code) {
        System.out.println("发送验证码成功");
    }
}
